#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <set>
#include <queue>

using namespace std;
using LL = long long;
using PII = pair<int, int>;

const int N = 1e5 + 10;

int n, m;
vector<double> e[N], w[N];

unordered_map<int, double> f;

double dfs(int u){
    if(f.count(u)){
        return f[u];  
    }

    double res = 0;
    for(int i = 0; i < e[u].size(); i ++){
        res += ((double)w[u][i] + dfs(e[u][i])) / (double)e[u].size();
    }

    f[u] = res;
    return res;
}


int main(){
#ifdef LOCALFLAG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif


    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);

    cin >> n >> m;
    int a, b, c;
    for(int i = 1; i <= m; i ++){
        cin >> a >> b >> c;
        e[a].push_back(b);
        w[a].push_back(c);
    }

    f[n] = 0;
    double t =  dfs(1);
    printf("%.2lf", t);

    return 0;
}